package bean;

import java.math.BigDecimal;
import java.util.LinkedList;
import java.util.List;

/**
 * @author 栋
 * @date 2022/12/3
 * @description
 */
public class Car {
    private List<Orders> lst;
    private int cnt;
    private BigDecimal totalPrice;

    public Car() {
        this.totalPrice=new BigDecimal(0);
        this.cnt=0;
        this.lst=new LinkedList<>();
    }
    public void add(Orders o){
        this.lst.add(o);
        this.cnt++;
        BigDecimal total_price = o.getTotal_price();
        this.totalPrice=this.totalPrice.add(total_price);
    }

    public void del(Orders o){
        for(int i=0;i<this.lst.size();i++){
            if(lst.get(i).getItem_id().equals(o.getItem_id())){
                lst.remove(i);
                totalPrice.subtract(o.getTotal_price());
                cnt--;
            }
        }
    }

    public void clearCar(){
        this.lst.clear();
        this.cnt=0;
        this.totalPrice=BigDecimal.valueOf(0);
    }

    public List<Orders> getLst() {
        return lst;
    }

    public void setLst(List<Orders> lst) {
        this.lst = lst;
    }

    public int getCnt() {
        return cnt;
    }

    public void setCnt(int cnt) {
        this.cnt = cnt;
    }

    public BigDecimal getTotalPrice() {
        return totalPrice;
    }

    public void setTotalPrice(BigDecimal totalPrice) {
        this.totalPrice = totalPrice;
    }
}
